#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main()
{
    umask(0); 
    int fd = open("log.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    if (fd == -1)
    {
        printf("fd:%d, errno:%d, errstring:%s\n", fd, errno, strerror(errno));
    }
    else printf("fd:%d, errno:%d, errstring:%s\n", fd, errno, strerror(errno));
    int cnt = 1;
    const char* msg = "aaa";
    while (cnt--)
    {
        char line[128];
        snprintf(line, sizeof(line), "%s, %d\n", msg, cnt);
        write(fd, line, strlen(line));
    }
    close(fd);
    return 0;
}
